package com.chinatsp.onlineapp.presenter;

import org.xutils.http.RequestParams;

import tsp.cn.http.BaseIDao;
import tsp.cn.http.interfac.INetResult;
import tsp.cn.http.tools.LogUtil;
import tsp.cn.http.tools.PreferenceUtils;

import android.content.Context;

import com.chinatsp.onlineapp.base.Config;
import com.chinatsp.onlineapp.bean.ActiveBean;
import com.chinatsp.onlineapp.bean.ReplaceTokenBean;
import com.google.gson.Gson;

public class ReplaceTokenDao extends BaseIDao{
	ReplaceTokenBean mReplaceTokenBean;
	
	public ReplaceTokenDao(Context context, INetResult iNetResult) {
		super(context, iNetResult);
		// TODO Auto-generated constructor stub
	}
	
    public ReplaceTokenBean getReplaceTokenBean(){
    	return mReplaceTokenBean;
    }
    
	public void postReplace() {
		String ucs_api_host = PreferenceUtils.getPreference("ucs_api_host");
		String factory_code = PreferenceUtils.getPreference("factory_code");
		String tuid = PreferenceUtils.getPreference("tuid_sv");
		
		String url = "http://"+ucs_api_host+"/"+factory_code+"/1.0/tu/"+tuid+"/replace/token/";
		
		//String tuid_sv = PreferenceUtils.getPreference("tuid_sv");
		String tuid_sv = PreferenceUtils.getPreference("tuid_sv");
		String access_token_sv = PreferenceUtils.getPreference("access_token_sv"); 
		
		RequestParams params = new RequestParams(url);
		
		params.setHeader("Cookie", "customer_key="+tuid_sv+";access_token="+access_token_sv+";");

		postRequest(params, Config.CODE_GET_REPLACE_TOKEN);
	}

	@Override
	public void onRequestSuccess(String result, int requestCode) {
		LogUtil.d( "ReplaceTokenDao onRequestSuccess");
		// TODO Auto-generated method stub
		mReplaceTokenBean = new Gson().fromJson(result, ReplaceTokenBean.class);
	}
}
